package mypodsync.device;

import java.io.File;
import java.util.TimerTask;

import mypodsync.service.Service;

public class DeviceVerifierTask extends TimerTask {
 
    private DeviceListener deviceListener;
    private Service service;
    private boolean active;
    
    public DeviceVerifierTask(DeviceListener deviceListener, Service service) {
        this.deviceListener = deviceListener;
        this.service = service;
        this.active = false;
    }
    
    public void run() {
        File device = new File(service.getFolderToLookup());
        if (device.canWrite()) {
            if (!active) {
                deviceListener.activate(service);
                active = true;
            }
        } else {
            if (active) {
                deviceListener.deactivate(service);
                active = false;
            }
        }
    }
}
 
